$(function(){
    $.fn.raty.defaults.path = '/by-webhtml/assets/image';
    $('.halfShow-true-demo').raty({readOnly: false, score: 5 });
    var id = $("#exampleDiscussId_update").val();
    if(id){
        $.ajax({
            type : "post",
            url : "htmlWeb/getExampleDiscuss",
            data: {"id" : id},
            async: false,
            success : function(data){
                var str = "";
                data = trimEmpty(data);
                $("#dName").val(data.name);
                $('.halfShow-true-demo').raty({readOnly: false, score: data.score });
                $("#dContent").val(data.content);
                $("#preview").attr("src","http://img.boyitongcheng.com/" + data.imgUrl);
            },
            error : function(data){
                console.log(data);
            }
        });
    }

    $(".save").click(function () {
        var options = {
            url: '/htmlWeb/submitExampleDiscuss',
            type: 'post',
            success: function (data) {
                $.ajaxSetup({cache: false});
                cancle();
            },
            error:function () {
                $.ajaxSetup({cache: false});
                tip("上传失败");
                cancle();
            }
        };
        $("#form").ajaxForm(options);
    });
});
function cancle() {
    var id = $("#exampleId_update").val();
    var jsPath = "../../by-webhtml/assets/js/system/system_discussList.js";
    $(".mainDiv").load("/htmlWeb/systemDiscussListHtml", '', function () {
        $("#exampleId").val(id);
        $.getScript(jsPath);
    });
}